<script setup lang="ts">
import type { goodsListItem } from '@/types/goods'
import { getShareUrl } from './sharePoster'

const emits = defineEmits<{
  (event: 'close'): void
  (event: 'showPoster'): void
}>()

const props = defineProps<{
  goods: goodsListItem
}>()

const onCpoyLink = () => {
  const shareUrl = getShareUrl(props.goods.id)

  uni.setClipboardData({
    data: shareUrl,
    success: function () {
      uni.showToast({
        title: '复制成功',
        icon: 'none',
      })
    },
  })

  emits('close')
}
const onShowSharePoster = () => {
  emits('close')
  emits('showPoster')
}
</script>

<template v-if="path == ''">
  <view class="panel">
    <view class="content">
      <!-- #ifdef MP-WEIXIN -->
      <button class="content-item" open-type="share">
        <image class="icon" src="/static/icons/wechat.svg" />
        <view class="text">微信好友</view>
      </button>
      <!-- #endif -->
      <button class="content-item" @tap="onShowSharePoster">
        <image class="icon" src="/static/icons/poster.svg" />
        <view class="text">生成海报</view>
      </button>
      <button class="content-item" @tap="onCpoyLink">
        <image class="icon" src="/static/icons/link.svg" />
        <view class="text">复制链接</view>
      </button>
    </view>
    <view class="footer">
      <view class="button" @tap="emits('close')"> 取消分享 </view>
    </view>
  </view>
</template>

<style lang="scss">
.panel {
  padding: 0 30rpx;
  border-radius: 10rpx 10rpx 0 0;
  position: relative;
  background-color: #fff;
}

.title {
  line-height: 1;
  padding: 40rpx 0;
  text-align: center;
  font-size: 32rpx;
  font-weight: normal;
  border-bottom: 1rpx solid #ddd;
  color: #444;
}

.close {
  position: absolute;
  right: 24rpx;
  top: 24rpx;
  font-size: 40rpx;
}

.content {
  display: flex;
  justify-content: cneter;

  .content-item {
    margin-top: 20rpx;
    background-color: transparent;
    border: none;
  }

  ::after {
    border: none;
  }

  .icon {
    width: 80rpx;
    height: 80rpx;
  }

  .text {
    font-size: 30rpx;
  }
}

.footer {
  display: flex;
  justify-content: space-between;
  padding: 20rpx 0 40rpx;
  font-size: 28rpx;
  color: #444;

  .button {
    flex: 1;
    height: 72rpx;
    text-align: center;
    line-height: 72rpx;
    margin: 0 20rpx;
    border-radius: 72rpx;
    color: #fff;
    background-color: #ff5f3c;
  }
}

.action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx;
  background: #f5f5f5;

  .button {
    padding: 16rpx 32rpx;
    margin: 0 10rpx;

    background: #ff784d;
    color: #ffffff;

    border-radius: 40rpx;

    &:active {
      opacity: 0.8;
    }
  }

  .cancel {
    background: #b3b3b3;
    color: #ffffff;
  }
}
</style>
